package com.wu.online.service.base.exception;

import com.wu.online.common.base.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author lynn
 * @date 2020/7/23 - 21:55
 */
public class OnlineException extends RuntimeException {
    /**
     * 状态码
     */
    private Integer code;

    public Integer getCode() {
        return this.code;
    }

    /**
     * 接受状态码和消息
     *
     * @param code
     * @param message
     */
    public OnlineException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型
     *
     * @param resultCodeEnum
     */
    public OnlineException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "Exception{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
